﻿@using System.Web.UI.WebControls
@Html.DevExpress().GridView(
    settings => {
        settings.Name = "drillDownGridView";
        settings.KeyFieldName = "ConcreteLesson.ID";
        settings.CallbackRouteValues = new { Action = "GridViewPartial", Controller = "Journal" };
        settings.SettingsLoadingPanel.Mode = GridViewLoadingPanelMode.ShowOnStatusBar;
        settings.Styles.Header.ImageSpacing = Unit.Pixel(5);
        settings.Styles.Header.SortingImageSpacing = Unit.Pixel(5);
        settings.ClientSideEvents.BeginCallback = "OnGridViewBeginCallback";
        settings.ClientSideEvents.EndCallback = "OnGridViewEndCallback";
        settings.SettingsEditing.Mode = GridViewEditingMode.Inline;
        settings.SettingsEditing.UpdateRowRouteValues = new {Controller = "Journal", Action = "InlineEditingUpdatePartial"};
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.EditButton.Visible = true;

        settings.Columns.Add(column =>
        {
            column.FieldName = "ConcreteLesson.ID";
            column.Caption = "ID урока";
            column.ReadOnly = true;
            //column.Visible = false;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "Pupil.UserDetails.GlobalProfileID";
            column.Caption = "ID ученика";
            column.ReadOnly = true;
            //column.Visible = false;
        });
        settings.Columns.Add(column => {
            column.FieldName = "ConcreteLesson.JournalLesson.Order";
            column.Caption = "Номер урока";
            column.ReadOnly = true;
        });
        settings.Columns.Add(column => {
            column.FieldName = "ConcreteLesson.JournalLesson.TeacherSubject.SubjectID";
            column.Caption = "Предмет";
            column.ReadOnly = true;
        });
        settings.Columns.Add(column => {
            column.FieldName = "ConcreteLesson.Date";
            column.Caption = "Дата";
            column.ColumnType= MVCxGridViewColumnType.DateEdit;
            column.ReadOnly = true;
        });
        settings.Columns.Add(column => {
            column.FieldName = "Pupil.UserDetails.LastName";
            column.Caption = "Фамилия";
            column.ReadOnly = true;
        });
        settings.Columns.Add(column => {
            column.FieldName = "Pupil.UserDetails.FirstName";
            column.Caption = "Имя";
            column.ReadOnly = true;
        });
        settings.Columns.Add(column => {
            column.FieldName = "Pupil.UserDetails.PatronymicName";
            column.Caption = "Отчество";
            column.ReadOnly = true;
        });
        settings.Columns.Add(column => {
            column.FieldName = "Mark1";
            column.Caption = "Оценка 1";
            column.ColumnType = MVCxGridViewColumnType.SpinEdit;
            var spinEditProperties = column.PropertiesEdit as SpinEditProperties;
            spinEditProperties.NumberType = SpinEditNumberType.Integer;
            spinEditProperties.MinValue = 0;
            spinEditProperties.MaxValue = 10;
        });
        settings.Columns.Add(column => {
            column.FieldName = "Mark2";
            column.Caption = "Оценка 2";
            column.ColumnType = MVCxGridViewColumnType.SpinEdit;
            var spinEditProperties = column.PropertiesEdit as SpinEditProperties;
            spinEditProperties.NumberType = SpinEditNumberType.Integer;
            spinEditProperties.MinValue = 0;
            spinEditProperties.MaxValue = 10;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "IsAbsent";
            column.Caption = "Пропуск";
            column.ColumnType = MVCxGridViewColumnType.CheckBox;
        });
        settings.BeforeGetCallbackResult = (sender, e) => {
            if (ViewBag.IsResetGridViewPageIndex != null && ViewBag.IsResetGridViewPageIndex)
                ((MVCxGridView)sender).PageIndex = 0;    
        };
        //settings.PreRender = (sender, e) =>
        //{
        //    ((MVCxGridView)sender).StartEdit(0);
        //};
    }).Bind(Model).GetHtml()